//
//  ALPS_TSVoiceCCell.m
//  Alps
//
//  Created by dllo on 16/6/17.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ALPS_TSVoiceCCell.h"

@implementation ALPS_TSVoiceCCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.smallView = [[UIImageView alloc] init];
        self.smallView.layer.masksToBounds = YES;
        self.smallView.layer.cornerRadius = 40;
        self.smallView.layer.borderWidth = 1;
        self.smallView.layer.borderColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1.00].CGColor;
        self.smallView.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:_smallView];
        
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_titleLabel];
        
        self.introduceLabel = [[UILabel alloc] init];
        self.introduceLabel.font = [UIFont systemFontOfSize:14];
        self.introduceLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_introduceLabel];

        self.playView = [[UIImageView alloc] init];
        self.playView.image = [UIImage imageNamed:@"album_play"];
        [self.contentView addSubview:_playView];
        
        self.playsLabel = [[UILabel alloc] init];
        self.playsLabel.textColor = [UIColor grayColor];
        self.playsLabel.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:_playsLabel];
        
        self.lengthView = [[UIImageView alloc] init];
        self.lengthView.image = [UIImage imageNamed:@"search_hist_tag"];
        [self.contentView addSubview:_lengthView];
        
        self.lengthLabel = [[UILabel alloc] init];
        self.lengthLabel.textColor = [UIColor grayColor];
        self.lengthLabel.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:_lengthLabel];

        
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.smallView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(10);
        make.left.equalTo(self.contentView).offset(10);
        make.width.equalTo(80);
        make.height.equalTo(80);
        
    }];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(10);
        make.left.equalTo(self.smallView.right).offset(10);
        make.right.equalTo(self.contentView).offset(-10);
        make.height.equalTo(20);
    }];
    
    [self.introduceLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.bottom).offset(10);
        make.left.equalTo(self.smallView.right).offset(10);
        make.right.equalTo(self.contentView).offset(-10);
        make.height.equalTo(20);
    }];
    
    [self.playView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.introduceLabel.bottom).offset(14);
        make.left.equalTo(self.smallView.right).offset(10);
        make.width.equalTo(10);
        make.height.equalTo(10);
        
    }];
    
    [self.playsLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.introduceLabel.bottom).offset(10);
        make.left.equalTo(self.playView.right).offset(5);
        make.width.equalTo(60);
        make.height.equalTo(20);
        
    }];
    
    }


-(void)setModel:(ALPS_TSearchAllDModel *)model
{
    if (_model!= model) {
        _model = model;
        [self.smallView sd_setImageWithURL:[NSURL URLWithString:model.cover_path] placeholderImage:[UIImage imageNamed:@"PlaceHolder"]];
        
        self.titleLabel.text = model.title;
        
        if (model.count_play > 10000) {
            [self.playsLabel sizeToFit];
            self.playsLabel.text = [NSString stringWithFormat:@"%.1f万", model.count_play / 10000.0];
        }else
        {
            [self.playsLabel sizeToFit];
            self.playsLabel.text = [NSString stringWithFormat:@"%ld", model.count_play];
        }
        
        self.introduceLabel.text = [NSString stringWithFormat:@"by %@", model.nickname];
        
        
        
        NSInteger minutes = (long)self.model.duration / 60;
        NSInteger seconds = (long)self.model.duration % 60;
        
        
        

            self.lengthLabel.text = [NSString stringWithFormat:@"%02ld:%02ld", minutes, seconds];
            [self.lengthView makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.introduceLabel.bottom).offset(12);
                make.left.equalTo(self.playsLabel.right).offset(5);
                make.width.equalTo(15);
                make.height.equalTo(15);
                
            }];

            [self.lengthLabel makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.introduceLabel.bottom).offset(10);
                make.left.equalTo(self.lengthView.right).offset(5);
                make.right.equalTo(self.contentView).offset(-10);
                make.height.equalTo(20);
                
            }];
    }
    

}


@end
